/*
 * ContextualMenuItem.java
 * Copyright (C) 2007 Ezequiel Turovetzky
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
package ar.com.botonera.gui.menu.contextual;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JMenuItem;

/**
 * Clase abstracta que representa un &iacute;tem del men&uacute;
 * contextual mostrado al hacer click derecho sobre un bot&oacute;n de la botonera.
 * @author <a href="mailto:tezequiel@gmail.com">Ezequiel Turovetzky</a>
 * @version 1.0
 */
public abstract class ContextualMenuItem extends JMenuItem implements ActionListener, MouseListener {

    //~ Constructors -----------------------------------------------------------

    /**
     * Creates a new ContextualMenuItem object.
     * @param text Texto de este &iacute;tem.
     */
    public ContextualMenuItem(String text) {
        super(text);
        addActionListener(this);
        addMouseListener(this);
    }

    //~ Methods ----------------------------------------------------------------

	/**
     * Este metodo es invocado al hacerse click sobre este &iacute;tem
     * del men&uacute; contextual.
     */
    public abstract void onClick();
    
    @Override
    public final void actionPerformed(ActionEvent e) {
        onClick();
    }
    
    /**
     * Cambia el color de fondo de este &iacute;tem cuando el mouse
     * pasa por encima.
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseEntered(MouseEvent e) {
    	setBackground(Color.ORANGE);
    }
    
    /**
     * Cambia el color de fondo de este &iacute;tem cuando el mouse sale
     * del &aacute;rea de este &iacute;tem.
     * <br>De esta manera, se restaura el color original del componente,
     * que previamente ha sido cambiado por el m&eacute;todo <code>mouseEnter(java.awt.Event,int,int)</code>
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseExited(MouseEvent e) {
    	setBackground(Color.WHITE);
    }
    
    @Override
    public void mouseClicked(MouseEvent e) {}
    @Override
	public void mousePressed(MouseEvent e) {}
    @Override
	public void mouseReleased(MouseEvent e) {}    
}
